package com.example.jdbcdemo.controller;

import com.alibaba.fastjson.JSON;
import com.example.jdbcdemo.service.StatsStorageServiceInterface;
import com.example.jdbcdemo.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stats")
public class StatsStorageController {
    @Autowired
    StatsStorageServiceInterface statsStorageServiceInterface;

    @PostMapping("/storage")
    public JsonUtil statsStorage(){
        List<Map<String,Object>> list=statsStorageServiceInterface.statsNumCost();
        if (list.isEmpty()||list==null)
        {
            return new JsonUtil(400,"未找到相关记录","[]");
        }
        return new JsonUtil(0,"统计成功", JSON.toJSONString(list));
    }
}
